package threadpool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author sesshomaru
 * @date 2021/10/11 22:41
 *模拟newFixedThreadPool的oom
 */
public class FixedThreadPoolOOM {
    public static void main(String[] args) {
        ExecutorService newFixedThreadPool = Executors.newFixedThreadPool(1);
        for (int i = 0; i < Integer.MAX_VALUE; i++) {
            // 通过线程池执行线程任务
            newFixedThreadPool.execute(new SubTask());
        }
    }
}

class SubTask implements Runnable{
    @Override
    public void run() {
        try {
            Thread.sleep(1000000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName());
    }
}
